//
//  XFTopview.swift
//  mxfweibo
//
//  Created by apple1 on 15/12/20.
//  Copyright © 2015年 莫祥富. All rights reserved.
//

import UIKit

import SDWebImage

class XFTopview: UIView {
    
    var status: XFStatus? {
        didSet {
        
            if let profile_image_url = status?.user?.profile_image_url {
                
                let url = NSURL (string: profile_image_url)
                iconView.sd_setImageWithURL(url, placeholderImage: UIImage(named: "avatar"))
            }
            
            nameLabel.text = status?.user?.screen_name
            
            timeLabel.text = "2分钟之后"
            
            sourceLabel.text = "来自我的iPhone 8s"
            
            vipView.image = status?.user?.mbrankImage
            
            verifiedView.image = status?.user?.verifiedImage
        }
    }
    
    
    

    override init(frame: CGRect) {
        super.init(frame: frame)
        
//        self.backgroundColor = UIColor.greenColor()
        
        prepareUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func prepareUI() {
        
        addSubview(separatorView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        addSubview(vipView)
        addSubview(verifiedView)
        
        
        separatorView.ff_AlignInner(type: ff_AlignType.TopLeft, referView: self, size: CGSize(width: UIScreen.mainScreen().bounds.width, height: 10))
        
        iconView.ff_AlignVertical(type: ff_AlignType.BottomLeft, referView: separatorView, size: CGSize(width: 35, height: 35), offset: CGPoint(x: 8, y: 8))
        
        nameLabel.ff_AlignHorizontal(type: ff_AlignType.TopRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        timeLabel.ff_AlignHorizontal(type: ff_AlignType.BottomRight, referView: iconView, size: nil, offset: CGPoint(x: 8, y: 0))
        
        sourceLabel.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: timeLabel, size: nil, offset: CGPoint(x: 8, y: 0))
        
        vipView.ff_AlignHorizontal(type: ff_AlignType.CenterRight, referView: nameLabel, size: CGSize(width: 14, height: 14), offset: CGPoint(x: 8, y: 0))
        
        verifiedView.ff_AlignInner(type: ff_AlignType.BottomRight, referView: iconView, size: CGSize(width: 17, height: 17), offset: CGPoint(x: 8.5, y: 8.5))
    }
    
    //MARK: - 懒加载
    
    //cell的分割线
    private lazy var separatorView: UIView = {
        
        let view = UIView()
        view.backgroundColor = UIColor(white: 0.81, alpha: 1)
        return view
    }()
    
    //用户头像
    private lazy var iconView : UIImageView = UIImageView(image: UIImage(named: "avatar"))
    
    //用户名称
    private lazy var nameLabel : UILabel = {
        
        let label = UILabel()
        
        label.textColor = UIColor.darkGrayColor()
        label.font = UIFont.systemFontOfSize(14)
    
        return label
    }()
    
    //微博时间
    private lazy var timeLabel : UILabel = {
       
        let label = UILabel()
        
        label.textColor = UIColor.orangeColor()
        label.font = UIFont.systemFontOfSize(9)
        
        return label
    }()
    
    //微博来源
    private lazy var sourceLabel : UILabel = {
       
        let label = UILabel()
        
        label.textColor = UIColor.lightGrayColor()
        label.font = UIFont.systemFontOfSize(9)
        
        return label
    }()
    
    //会员等级
    private lazy var vipView : UIImageView = UIImageView(image: UIImage(named:"common_icon_membership_expired"))
    
    //认证图标
    private lazy var verifiedView : UIImageView = UIImageView(image:nil)
    
    

}
